package ModelLag;
import java.util.ArrayList;


/**
 * The LoanContainer class holds up to several object of the type Loan.
 * 
 * @author (Lackshan, Mikkel, Nick, patrick, Simon, Yousef) 
 * @project (Tema design)
 * @version (2014.11.05)
 */
public class LoanContainer
{
    private static LoanContainer instance = null;
    private ArrayList<Loan> loans;

    /**
     * Constructor for objects of class DVDContainer
     */
    private LoanContainer(){
        loans = new ArrayList<Loan>();
    }
    
    /**
     * Returns an instance of LoanContainer
     * 
     * @return an instance of LoanContainer
     */ 
    public static LoanContainer getInstance(){
        if(instance == null){
            instance = new LoanContainer();
        }
        return instance;
    }

    /**
     * Adds a Loan object to the loans Arraylist in the LoanContainer class
     * 
     * @param l is the user input for a specific Loan
     */
    public void addLoan(Loan l){
        loans.add(l);
    }
    
    /**
     * Gets the loan
     * 
     * @return Lone Object
     */
    public Loan findLoan(String serilNumber){
        int i = 0;
        boolean found = false;
        Loan returnLoan = null;
        while (!found && i<= loans.size()){
            Loan l = loans.get(i);
            if(l.GetCopy().getSerialNumber().equals(serilNumber)){
                found = true;
                returnLoan = l;
            }
            i++;
        }
        return returnLoan;
    }

    /**
     * This method is used to delete a specified loan object using that loans ?
     * 
     * @param l is the user input for a specific loan
     */
    public void deleteLoan(Loan l){
        loans.remove(l);
    }
    
}
